
<?php
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

error_reporting(E_ALL);
include_once('../controller/includes/db_access.php');

function transforme_HTML($chaine, $longueur = null) {
// Aide à empêcher les attaques XSS
// Supression des espaces inutiles.
    $chaine = trim($chaine);
// Empêche des problèmes potentiels avec le codec Unicode.
    $chaine = utf8_decode($chaine);
// HTMLise les caractères spécifiques à HTML.
    $chaine = htmlentities($chaine, ENT_NOQUOTES);
    $chaine = str_replace("#", "&#35;", $chaine);
    $chaine = str_replace("%", "&#37;", $chaine);
    $longueur = intval($longueur);
    if ($longueur > 0) {
        
        $chaine = substr($chaine, 0, $longueur);
    
        
    }
    return $chaine;
}

require_once('../controller/includes/random_password.php');

error_reporting(0);

//begin script voor bewerk eindproducten 
if (isset($_POST['actType']) && ($_POST['actType'] == 'opslaan')) {



    $from = $_POST['geldig_van'];
    $to = $_POST['geldig_tot'];

    $from = date('d-m-Y', strtotime($from));
    $to = date('d-m-Y', strtotime($to));

    $nodays = (strtotime($to) - strtotime($from)) / (60 * 60 * 24); //it will count no. of days






    if (!empty($_POST['name'])
            && !empty($_POST['type'])
            && !empty($_POST['code'])
            && !empty($_POST['geldig_van'])
            && !empty($_POST['geldig_tot'])
    ) {


//kijk of aantal dagen is groot dan 0
        if ($nodays > 0) {


            $naam = $_POST['name'];
;
           $code = $_POST['code'];
            $geldig_van = $_POST['geldig_van'];
            $geldig_tot = $_POST['geldig_tot'];
            $aktief = $_POST['aktief'];

            if ($_POST['type'] == 'C') {
                $type = $_POST['type'];
                if ($_POST['waarde'] > 0) {

            $korting = $_POST['waarde'];
          $query_korting= mysql_query("INSERT INTO cadeaubon(naam, cadeaubon.type, korting, cadeaubon.code, geldig_van, geldig_tot, aktief)VALUE('$naam', '$type',$korting, '$code', '$geldig_van','$geldig_tot', '$aktief')");         
                      
            header('Location: korting_list.php');

                } else {
                     //$deId = $_GET['pid'];
                    $Error = "Controleren of de veld waarde is ingevuld!";

                }
            } elseif ($_POST['type'] == 'A') {
                 $type = $_POST['type'];
                if ($_POST['korting'] > 0) {
                    
                    $korting = $_POST['korting'];
                    

                 $query_korting= mysql_query("INSERT INTO cadeaubon(naam, cadeaubon.type, korting, cadeaubon.code, geldig_van, geldig_tot, aktief)VALUE('$naam', '$type',$korting, '$code', '$geldig_van','$geldig_tot', '$aktief')");         
           
           header('Location: korting_list.php');
                    
                    
                    
                } else {
                    //$deId = $_GET['pid'];
                    $Error = "Controleren of de veld Percentage is ingevuld!";
                   // exit ();
                }
            }

// $aValues['geldig_tot'] = STR_TO_DATE($_POST['geldig_tot'], '%d/%m/%Y');



        } else {
            header('Location: korting_edit.php?pid=' . $_GET['pid'] . '&error=2');
            exit;
        }
    } else {
        header('Location: korting_edit.php?pid=' . $_GET['pid'] . '&error=3');
        exit;
    }
}


?>

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <!--[if lt IE 9]>
        <script
        src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->
        <link rel="stylesheet" href="styles/style.css" type="text/css" />
        <!--[if lte IE 7]>
        <link rel="stylesheet" href="style_ie.css" />
        <![endif]-->
        <title>dbme!!!!</title>
        <link rel="stylesheet" href="../css/themes/base/jquery.ui.all.css" />
        <script type="text/javascript" src="../js/lib/jquery.js"></script>
        <script type="text/javascript" src="../js/jquery-1.7.2.js"></script>
        <script type="text/javascript" src="../js/lib/chili-1.7.pack.js"></script>
        <script type="text/javascript" src="../js/lib/jquery.easing.js"></script>
        <script type="text/javascript" src="../js/lib/jquery.dimensions.js"></script>
        <script type="text/javascript" src="../js/jquery.ui.core.js"></script>
        <script type="text/javascript" src="../js/jquery.ui.widget.js"></script>
        <script type="text/javascript" src="../js/jquery.ui.datepicker.js"></script>
            <SCRIPT type="text/javascript">
                <!--

                function checkForm(f) {
                    var re = new RegExp("^[0-9a-z]([-_.]?[0-9a-z_])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,}$",'i');

                    if (f.naam.value == "") {
                        alert( "Je hebt de naam nog niet ingevuld!" );
                        document.getElementById("naam").style.backgroundColor="#708CA2";
                        f.naam.focus();
                        return false ;
                    }
                    
                     if (f.Cadeaubon.value == "") {
                        alert( "Je hebt Cadeaubon waarden nog niet ingevuld!" );
                        document.getElementById("Cadeaubon").style.backgroundColor="#708CA2";
                        f.Cadeaubon.focus();
                        return false ;  
                    }else{
                        if (f.aktie.value == "" ) {
                        alert( "Je hebt Aktie nog niet ingevuld!" );
                        document.getElementById("aktie").style.backgroundColor="#708CA2";
                        f.aktie.focus();
                        return false ;
                    }
                }
                    
                     if (f.datepicker.value == "") {
                        alert( "Je hebt Geldig van nog niet ingevuld!" );
                        document.getElementById("datepicker").style.backgroundColor="#708CA2";
                        f.datepicker.focus();
                        return false ;
                    }
                    
                     if (f.datepicker1.value == "") {
                        alert( "Je hebt Geldig tot nog niet ingevuld!" );
                        document.getElementById("datepicker1").style.backgroundColor="#708CA2";
                        f.datepicker1.focus();
                        return false ;
                    }
                    
                    return true;
                }
                
                  ////jquery datepicker met aangepast datumformaat
  
$(function() {
$('input#datepicker,#datepicker1').datepicker({
dateFormat: 'yy-mm-dd',
changeMonth: false,
changeYear: false
},
$.datepicker.regional['nl']);
});

                //-->
</SCRIPT>
       
</head>
<body>
    <div id="bloc_page">
        <header>
            <a href="#"><img src="../images/dBmelogo.png" alt="referentie" alt="dbme!" /></a>
        </header>  
        <nav>
<?php include_once('header.php'); ?>
        </nav>
        <section>
            <aside>
                <!--right side baar -->  
            </aside>

            <article>               


                
<table width="800" border="0" cellspacing="5" cellpadding="5">
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="sform" id="sform" enctype="multipart/form-data" onSubmit="return checkForm(this)">
<input type="hidden" name="actType" value="opslaan">
                                                                            
                <tr>
                    <td width="100" valign="top"> &nbsp;&nbsp;&nbsp;</td>
                    <td width="500" valign="top" COLSPAN="2"> <?php
if (isset($Error)) {
    echo '<font color="red">'.$Error.'</font>';
}
?></td>

                    <td width="200" valign="top"> &nbsp;&nbsp;&nbsp;</td>




            <tr>


                <td  valign="top"> Naam:</td>
                <td valign="top">

                    <input type="text" name="name" value="" class="inp" id="naam" onblur="this.style.backgroundColor='#fff';"  style="width:200px" /><font color="red" >*</font>

                </td>
                <td valign="top" colspan="2">

                </td>
            </tr>
                                                                           
                <tr>
                    
                    <td colspan="4" height="30" valign="top"> &nbsp;&nbsp;&nbsp;</td>
                    
                </tr>

            <tr>
              <td  valign="top"> Dit is een:</td>
                <td valign="top">
                    <input name="type" type="radio" value="C" id="Cadeaubon"/> Kortingsbedrag (een malig gebruik!) <br /> <br />
                    <input name="type" type="radio" value="A" id="aktie" /> Kortingspercentage
               </td>
              <td>
                waard &nbsp;&nbsp<input type="text" name="waarde" value="" class="inp" onblur="this.style.backgroundColor='#fff';"  style="width:60px" /> &euro;<br />
                percentage &nbsp;<input type="text" name="korting" value="" class="inp" onblur="this.style.backgroundColor='#fff';"  style="width:60px" /> %
              </td>
               <td  valign="top"></td>
            </tr>
             <tr>
                    
                    <td colspan="4" height="30" valign="top"> &nbsp;&nbsp;&nbsp;</td>
                    
                </tr>

            <tr>
                    <td valign="top"> code: </td>
                    <td valign="top">
                        

                        <input type="text" name="code" value="<?php echo $password;?>" class="inp" onblur="this.style.backgroundColor='#fff';"  style="width:150px" />
                    </td>
                    <td valign="top"> &nbsp;&nbsp;&nbsp;</td>
                    <td valign="top"> &nbsp;&nbsp;&nbsp;</td>

                </tr>
    
                <tr>
                    <td valign="top"> Geldig van: </td>
                    <td valign="top">  
                        <input type="text" name="geldig_van" value=""  id="datepicker" onblur="this.style.backgroundColor='#fff';"  style="width:150px" /><font color="red" >*</font>
                    </td>
                    <td valign="top"> &nbsp;&nbsp;&nbsp;</td>
                    <td valign="top"> &nbsp;&nbsp;&nbsp;</td>

                </tr>
                                <tr>
                    <td valign="top"> Geldig tot: </td>
                    <td valign="top">

                        <input type="text" name="geldig_tot" value="" id="datepicker1" onblur="this.style.backgroundColor='#fff';"  style="width:150px" /><font color="red" >*</font>
                    </td>
                    <td valign="top"> &nbsp;&nbsp;&nbsp;</td>
                    <td valign="top"> &nbsp;&nbsp;&nbsp;</td>

                </tr>
    <tr>
                    
                    <td colspan="4" height="30" valign="top"> &nbsp;&nbsp;&nbsp;</td>
                    
                </tr>
                    <tr>
                     <td valign="top"> Aktief</td>
                    <td valign="top">
                     <input name="aktief" type="radio" value="Y" /> Ja &nbsp;&nbsp;&nbsp;&nbsp;
                    <input name="aktief" type="radio" value="N" /> Nee
                   </td>
                   <td valign="top"> &nbsp;&nbsp;&nbsp;</td>
                   <td valign="top"> &nbsp;&nbsp;&nbsp;</td>
                   </tr>

        <tr>
            <td>&nbsp;</td>
            <td align="left">&nbsp;</td>
            <td align="left"><input type="submit" name="opslaan" id='cmdSubmit' value="save" /></td>
            
            <td align="left">&nbsp;</td>
        </tr>
            </form>
                </table>

            </article>

            <aside>
                <!--right side baar -->


            </aside>
        </section>

        <footer>  
            <p>Lorem ipsum dolor sit amet...</p>
            <p>Vivamus sed libero nec mauris pulvinar facilisis ut non sem...</p>
            <p>Phasellus ligula massa, congue ac vulputate non, dignissim at augue...</p>
        </footer>
    </div>
</body>
</html>